//
//  ZMainNavigationViewController.swift
//  swift-weibo
//
//  Created by zero on 17/3/19.
//  Copyright © 2017年 zero. All rights reserved.
//

import UIKit

class ZMainNavigationViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        self.interactivePopGestureRecognizer?.delegate = self
        
        navigationBar.isTranslucent = false
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        let count = viewControllers.count
        
        if count > 0{
            
            viewController.hidesBottomBarWhenPushed = true
            viewController.view.backgroundColor = UIColor.white
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(back))
        }
        
        
        super.pushViewController(viewController, animated: animated)

    }
    
    func back() {
        
        let _ = popViewController(animated: true)
    }
    
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        let count = viewControllers.count
        
        return count > 1
    }
}
